<%@page contentType="text/html;charset=UTF-8"%> <%@page
pageEncoding="UTF-8"%> <%@ page session="true" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<head>
<title>Welcome to Global Domination!</title>

</head>
<body>
<div id="fb-root"></div>
<script src="http://connect.facebook.net/en_US/all.js"></script>
<script>
//local 128354671037
//prod 230998268897
  FB.init({appId: '${api}', status: true, cookie: true, xfbml: true});
   
 FB.getLoginStatus(function(response) {
	  if (response.session) {
	    // redirect to controller
		 	gd_redirect();
	  } else {
		login();
	  }
	});
	  
	  
	  function login()
	  {
	  FB.login(function(response) {
  if (response.session) {
    if (response.perms) {
	//redirect to controller
    	gd_redirect();
    } else {
//console.log("user logged in and NOT granted the permission.. " );    
	// user is logged in, but did not grant any permissions
    }
  } else {
      // user is not logged in. What do we do?
  }
}, {perms:'read_stream,publish_stream'});
  
	  }


	  function gd_redirect()
	  {
		  FB.api('/me', function(response) {
			 setCookie("first_name",response.first_name,30);
			 setCookie("last_name",response.last_name,30); 
			 top.location.href="/facebookjs";
			});
					  
		 
	  }


	  function setCookie(c_name,value,expiredays)
	  {
	  var exdate=new Date();
	  exdate.setDate(exdate.getDate()+expiredays);
	  document.cookie=c_name+ "=" +escape(value)+
	  ((expiredays==null) ? "" : ";expires="+exdate.toUTCString());
	  }
</script>
Welcome to Global Domination!
Please wait. <a href="javascript:login()">Loading...</a>
<fb:login-button></fb:login-button>


</body>
</html>